function ico=newicon(data,varargin)
% newicon: Create a new icon object (rotable)
%
% SYNTAX:
%   ico = newicon(shape,prop1,value1,...)
%   ico = newicon(data,prop1,value1,...)
%   Return generated MADS.Icon object ico from specified shape (string) or vertex nodes (Nx2 matrix) and properties
%   This icon can be used as a logo of a player P by passing it to property P.ico
%   Type "newicon([])" to see available properties and their default values. 
%   
% See also NEWIMAGE, DRAWOBJ

%   Author: Hongbin Ma
%   Last updated: 2009-6-2 with MATLAB 6.5
%   Problems or suggestions? Email me: mathmhb[at]163.com

ico=struct('type','MADS.Icon',varargin{:});
ico=set_field(ico,'x',[0]);
ico=set_field(ico,'y',[0]);
ico=set_field(ico,'z',[0]);
ico=set_field(ico,'sx',1);
ico=set_field(ico,'sy',1);
ico=set_field(ico,'sz',1);
ico=set_field(ico,'size',1);
ico=set_field(ico,'color',[0 1 0]);
%ico=struct('type','MADS.Icon','x',[0],'y',[0],'size',1,'sx',1,'sy',1,'sz',1);
d=[];
switch class(data)
case 'double'
    d=data;
case 'char'
    d=get_data(data);
otherwise
    return;
end;
if ~isempty(d),
    ico=set_ico(ico,d);
end;

function ico=set_ico(ico,data)
ico.x=data(:,1);
ico.y=ico.x;
ico.z=ico.x;
if size(data,2)>1,
    ico.y=data(:,2);
end;
if size(data,2)>2,
    ico.z=data(:,3);
end;
    
function d=get_data(s)
d=[];
switch(s)
case 'point'
    d=[0;0]';
case 'circle'
    d=p_circle(1);
case 'line'
    d=p_line(-1,1);
case 'ellipse'
    d=p_ellipse(1,1);
case 'rect'
    d=p_rect(1,1);
case 'triangle'
    d=p_triangle(1,0,pi/6);
otherwise
end;
